package pers.zhang.dao.baseDao;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class BaseDaoImpl<T> extends SqlSessionDaoSupport implements BaseDao<T>{
    @Autowired
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
        super.setSqlSessionFactory(sqlSessionFactory);
    }
    //mapper映射的路径
    private String ns;
    public String getNs() {
        return ns;
    }
    public void setNs(String ns) {
        this.ns = ns;
    }

    public T findone(T entity) {
        return this.getSqlSession().selectOne(ns + ".findone", entity);
    }

    public List<T> find(Map map) {
        List<T> oList = this.getSqlSession().selectList(ns + ".find", map);
        return oList;
    }
    public List<T> finds() {
        List<T> oList = this.getSqlSession().selectList(ns+".finds");
        return oList;
    }
    public List<T> findtype(T entity) {
        List<T> oList = this.getSqlSession().selectList(ns+".findtype",entity);
        return oList;
    }
    public T get(Integer id) {

        return this.getSqlSession().selectOne(ns + ".get", id);
    }

    public void insert(T entity)
    {

        this.getSqlSession().insert(ns + ".insert", entity);
    }

    public Integer insertOrder(T entity)
    {

        return  this.getSqlSession().insert(ns + ".insertOrder", entity);
    }

    public void update(T entity) {
        this.getSqlSession().update(ns + ".update", entity);
    }

    public void deleteById(Serializable id) {
        this.getSqlSession().delete(ns + ".deleteById", id);
    }
    public void deleteByIds(Map ids) {
        this.getSqlSession().delete(ns + ".deleteByIds",ids);
    }

    public void delete(Serializable[] ids) {

        this.getSqlSession().delete(ns + ".delete", ids);
    }
}
